package cn.enilu.flash.dao.park;


import cn.enilu.flash.bean.entity.park.ParkingCarRef;
import cn.enilu.flash.bean.entity.park.ParkingContract;
import cn.enilu.flash.dao.BaseRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.Date;
import java.util.List;


public interface ParkingCarRefRepository extends BaseRepository<ParkingCarRef,Long>{

    List<ParkingCarRef> findByParkingIdAndState(Long id, Integer state);

    @Modifying
    @Query(nativeQuery = true, value = "UPDATE parking_car_ref SET `state`=1 WHERE \n" +
            "start_date <= now() AND end_date >= now()")
    void modifyActive();

    @Modifying
    @Query(nativeQuery = true, value = "UPDATE parking_car_ref SET `state`=0 WHERE \n" +
            "end_date < now()")
    void modifyDisable();

    @Modifying
    @Query(nativeQuery = true, value = "update parking_info a, parking_contract b \n" +
            "set a.owner_flag=0 \n" +
            "where a.id=b.parking_id \n" +
            "and b.end_date<now()")
    void modifyParkingOwnerFlag();
}

